package com.tdg.qywx.controller;

import com.alibaba.fastjson.JSONObject;
import com.tdg.qywx.mapper.PerMapper;
import com.tdg.qywx.model.VW_TDG_UPH_EMP;
import com.tdg.qywx.model.tb_tdg_uph_emp;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tdg/syn")
public class SearchController {
    private static final Logger _logger = LoggerFactory.getLogger(SearchController.class);
    @Autowired
    private PerMapper perMapper;

    //上下线提供提供接口，供宇视调用;如果返回是1，则开闸; 返回是0，则不开闸:
    @RequestMapping("/checkPass")
    @Operation(summary = "闸机")
    public JSONObject checkPass(@RequestParam String workCode){
        JSONObject r  = new JSONObject();

        tb_tdg_uph_emp empInfo = perMapper.findEmpInfoById(workCode);
        if (empInfo == null){
            r.put("msg","工号:"+workCode+"属于非IMS系统人员名单,允许出门");
            r.put("isPass",1);
        } else {
            r.put("msg","工号:"+workCode+",姓名:"+empInfo.getEMP_NAME()+",该员工已下线,允许开闸");
            r.put("isPass",1);

            List<VW_TDG_UPH_EMP> personList = perMapper.findOnlineEmp(workCode,null,null,null);
            for (int i= 0 ;i<personList.size();i++){
                VW_TDG_UPH_EMP person = personList.get(i);
                //如果当前人员在线  则返回0 不开闸机
                if(person.getSTATE()==0){//上线状态 返回0  不开闸
                    r.put("msg","工号:"+workCode+",姓名:"+person.getEMP_NAME()+",该员工未下线");
                    r.put("isPass",0);
                    break;
                }
            }
        }
        _logger.info("闸机:{}",r.toJSONString());
        return r;
    }

}
